package com.maybach.workflow.common.api;

import com.maybach.workflow.common.api.enums.WFContextKeyEnum;
import com.maybach.workflow.common.api.node.BaseNode;
import com.maybach.workflow.common.model.FlowDO;
import com.maybach.workflow.common.model.FlowTaskActorDO;
import com.maybach.workflow.common.model.FlowTaskDO;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by houenxun on 16/1/20.
 */
public class WorkFlowContext {
    public FlowChain getThisFlowChain() {
        return this.thisFlowChain;
    }

    public void setThisFlowChain(FlowChain thisFlowChain) {
        this.thisFlowChain = thisFlowChain;
    }

    private FlowChain thisFlowChain;
    private FlowDO thisFlow;

    public FlowDO getThisFlow() {
        return thisFlow;
    }

    public void setThisFlow(FlowDO thisFlow) {
        this.thisFlow = thisFlow;
    }

    private BaseNode thisNode;

    public List<FlowTaskActorDO> getTaskActorDOList() {
        return taskActorDOList;
    }

    public void setTaskActorDOList(List<FlowTaskActorDO> taskActorDOList) {
        this.taskActorDOList = taskActorDOList;
    }

    private List<FlowTaskActorDO> taskActorDOList;

    private FlowTaskActorDO taskActor;

    private FlowTaskDO thisTask;
    private String rejectToAction;

    public String getRejectToAction() {
        return rejectToAction;
    }

    public void setRejectToAction(String rejectToAction) {
        this.rejectToAction = rejectToAction;
    }

    public FlowTaskDO getLastTask() {
        return lastTask;
    }

    public void setLastTask(FlowTaskDO lastTask) {
        this.lastTask = lastTask;
    }

    private FlowTaskDO lastTask; // 上一个任务 即父任务

    public FlowTaskDO getThisTask() {
        return thisTask;
    }

    public void setThisTask(FlowTaskDO thisTask) {
        this.thisTask = thisTask;
    }

    public BaseNode getThisNode() {
        return thisNode;
    }

    public void setThisNode(BaseNode thisNode) {
        this.thisNode = thisNode;
    }

    private Long bizId;
    private String bizType;

    private String actionName;
    private Map<String, Object> args = new HashMap<String, Object>();
    private Map<String, Object> bizData = new HashMap<String, Object>();

    public Map<String, Object> getBizData() {
        return bizData;
    }

    public void setBizData(Map<String, Object> bizData) {
        this.bizData = bizData;
    }


    public Long getBizId() {
        if (null != thisFlow) {
            return thisFlow.getBizId();
        }

        return bizId;
    }

    public void setBizId(Long bizId) {
        this.bizId = bizId;
        bizData.put(WFContextKeyEnum.bizId.name(), bizId);
    }

    public String getActionName() {
        return actionName;
    }

    public void setActionName(String actionName) {
        this.actionName = actionName;
    }

    public Map<String, Object> getArgs() {
        return args;
    }

    public void setArgs(Map<String, Object> args) {
        this.args = args;
    }


    public BaseNode getTaskNode(String action) {
        if (action == null) {
            return null;
        }
        BaseNode baseNode = null;
        if (thisFlowChain != null) {
            baseNode = thisFlowChain.getMap().get(action);
        }

        return baseNode;

    }

    public FlowTaskActorDO getTaskActor() {
        return taskActor;
    }

    public void setTaskActor(FlowTaskActorDO taskActor) {
        this.taskActor = taskActor;
    }

    public String getBizType() {
        if (null != thisFlow) {
            return thisFlow.getBizType();
        }
        return bizType;
    }

    public void setBizType(String bizType) {
        this.bizType = bizType;
        bizData.put(WFContextKeyEnum.bizType.name(), bizType);
    }

    public FlowChain getFlowChain() {
        return this.getThisFlowChain();
    }
}
